package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.AlbumAddNewDTO;
import cn.tedu.csmall.product.pojo.dto.AlbumUpdateDTO;
import cn.tedu.csmall.product.pojo.vo.AlbumStandardVO;
import cn.tedu.csmall.product.service.IAlbumService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import javax.validation.Valid;
import java.util.List;


/**
 * 处理相册相关请求的控制器
 *
 * @author java@tedu.cn
 * @version 0.0.1
 */

@RestController
@RequestMapping("/albums")
@Api(tags = "3.相册管理模块")
@Slf4j
public class AlbumController {

    @Autowired
    IAlbumService albumService;

    @ApiOperation("添加相册")
    @PostMapping("/add-new")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(@Valid AlbumAddNewDTO albumAddNewDTO){
        System.out.println(("准备处理添加相册请求..."));
        System.out.println(albumAddNewDTO);

        albumService.addNew(albumAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("根据id删除相册")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id" ,value = "相册id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/deleteById")
    public JsonResult<Void> deleteById(@PathVariable Long id){
        log.debug("开始处理【删除相册】请求，id={}",id);
        albumService.delete(id);
        return JsonResult.ok();
    }

    @ApiOperation("根据id修改相册详情")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id",value = "相册id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/updateById")
    public JsonResult<Void> updateById(@PathVariable Long id, AlbumUpdateDTO albumUpdateDTO){
        log.debug("开始处理【修改相册详情】请求，id={}，albumUpdateDTO={}",id,albumUpdateDTO);
        albumService.update(id,albumUpdateDTO);
        return JsonResult.ok();
    }

    @ApiOperation("根据id获取相册表的详细信息")
    @GetMapping("/{id:[0-9]+}")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id",value = "相册id",required = true,dataType = "long")
    public JsonResult<AlbumStandardVO> getAlbumStandardVO(@PathVariable Long id){
        log.debug("即将处理【根据id获取相册表的详细信息】请求");
        AlbumStandardVO album = albumService.getAlbumStandardVO(id);
        return JsonResult.ok(album);
    }

    @GetMapping("")
    @ApiOperation("相册列表")
    @ApiOperationSupport(order = 410)
    public JsonResult<List<AlbumStandardVO>> list(){
        log.debug("处理相册列表请求：");
        List<AlbumStandardVO> list = albumService.list();
        return JsonResult.ok(list);
    }
}
